package JAVA300.第十章IO;

import java.io.*;

/**
 * 学习打印流
 */

public class IO_Study15_PrintStream {
    public static void main(String[] args) {
        PrintStream printStream = System.out;
        printStream.println("测试打印流");
        printStream.println(true);

        try {
            printStream = new PrintStream(new BufferedOutputStream(new FileOutputStream("IO_Study14.txt")),true);
            printStream.println("测试打印流");
            printStream.println(true);
            printStream.flush();//缓冲流就记得刷新--构造函数里传true可引入自动刷新

            //重定向输出端
            System.setOut(printStream);
            System.out.println("change");
            //重定向回输出台
            System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true));
            System.out.println("back");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
}
